﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace IllusionUtility.GetUtility
{
	// Token: 0x02000634 RID: 1588
	public static class GameObjectEx
	{
		// Token: 0x060025FB RID: 9723 RVA: 0x00146370 File Offset: 0x00144570
		public static T Get<T>(this GameObject obj) where T : MonoBehaviour
		{
			T component = obj.GetComponent<T>();
			if (!component)
			{
				global::Debug.LogError("Expected to find component of type " + typeof(T) + " but found none", obj);
			}
			return component;
		}

		// Token: 0x060025FC RID: 9724 RVA: 0x001463B4 File Offset: 0x001445B4
		public static T SearchComponent<T>(this GameObject obj, string searchName) where T : MonoBehaviour
		{
			T[] componentsInChildren = obj.GetComponentsInChildren<T>(true);
			foreach (T result in componentsInChildren)
			{
				if (searchName == result.name)
				{
					return result;
				}
			}
			return (T)((object)null);
		}

		// Token: 0x060025FD RID: 9725 RVA: 0x00146408 File Offset: 0x00144608
		public static GameObject[] CreateChild(this GameObject topObj, string pathName)
		{
			GameObject gameObject = null;
			List<GameObject> list = new List<GameObject>();
			foreach (string name in pathName.Split(new char[]
			{
				'/'
			}))
			{
				GameObject gameObject2 = new GameObject(name);
				list.Add(gameObject2);
				if (gameObject != null)
				{
					gameObject2.transform.SetParent(gameObject.transform);
				}
				gameObject = gameObject2;
			}
			list[0].transform.SetParent(topObj.transform);
			return list.ToArray();
		}
	}
}
